package com.ruoyi.basicsystem.controller;

import com.ruoyi.basicsystem.domain.ZnDepot;
import com.ruoyi.common.utils.SecurityUtils;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicsystem.domain.ZnInOutItem;
import com.ruoyi.basicsystem.service.IZnInOutItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收支项目Controller
 * 
 * @author nexiaozi
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/basicsystem/inoutitem")
public class ZnInOutItemController extends BaseController
{
    @Autowired
    private IZnInOutItemService znInOutItemService;

    /**
     * 查询收支项目列表
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZnInOutItem znInOutItem)
    {
        startPage();
        List<ZnInOutItem> list = znInOutItemService.selectZnInOutItemList(znInOutItem);
        return getDataTable(list);
    }

    /**
     * 导出收支项目列表
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:export')")
    @Log(title = "收支项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnInOutItem znInOutItem)
    {
        znInOutItem.setTenantId(SecurityUtils.getTenantId());
        List<ZnInOutItem> list = znInOutItemService.selectZnInOutItemList(znInOutItem);
        ExcelUtil<ZnInOutItem> util = new ExcelUtil<ZnInOutItem>(ZnInOutItem.class);
        util.exportExcel(response, list, "收支项目数据");
    }

    /**
     * 获取收支项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(znInOutItemService.selectZnInOutItemById(id));
    }

    /**
     * 新增收支项目
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:add')")
    @Log(title = "收支项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnInOutItem znInOutItem)
    {
        return toAjax(znInOutItemService.insertZnInOutItem(znInOutItem));
    }

    /**
     * 修改收支项目
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:edit')")
    @Log(title = "收支项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnInOutItem znInOutItem)
    {
        return toAjax(znInOutItemService.updateZnInOutItem(znInOutItem));
    }

    /**
     * 删除收支项目
     */
    @PreAuthorize("@ss.hasPermi('basicsystem:inoutitem:remove')")
    @Log(title = "收支项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(znInOutItemService.deleteZnInOutItemByIds(ids));
    }

    /**
     * 查询收支项目下拉列表
     */
    @PreAuthorize("@ss.hasAnyPermi('basicsystem:accountheadsr:list')")
    @GetMapping("/selectlist")
    public AjaxResult selectlist(ZnInOutItem znInOutItem)
    {
        znInOutItem.setDeleteFlag("0");
        znInOutItem.setTenantId(SecurityUtils.getLoginUser().getUser().getTenantId());
        List<ZnInOutItem> list = znInOutItemService.selectZnInOutItemList(znInOutItem);
        return AjaxResult.success(list);
    }
}
